import os
import sys
import time
from main_util import start_access_control, set_test_database, set_database_by_policy_file

from python_part.PolicyStoreModule import PolicyStoreModule

from GlobaLogger import Log
log = Log(__name__).getlog()

def work_flow():
    # 0. 全局变量与配置
    # 1. 创建保存策略的类
    policy_save_path = os.path.join('.', 'for_code_running', 'policy_store')
    tmp_path = os.path.join('.', 'for_code_running', 'tmp')
    policy_store_module = PolicyStoreModule(policy_save_path, tmp_path)
    policy_store_module.load_database_from_file(policy_save_path)
    # 2. 启动
    start_access_control(policy_store_module)

if __name__ == '__main__':
    # 0. 全局变量与配置
    # 1. 创建保存策略的类
    policy_save_path = os.path.join('.', 'for_code_running', 'policy_store')
    tmp_path = os.path.join('.', 'for_code_running', 'tmp')
    policy_store_module = PolicyStoreModule(policy_save_path, tmp_path)

    # 2. 载入测试用 策略库（有三种方式）
    # policy_store_module.load_database_from_file(policy_save_path)
    # set_test_database(policy_store_module)
    set_database_by_policy_file(policy_store_module, "policy.txt")
    # 3. 启动
    start_access_control(policy_store_module)
